<script lang="tsx">
/**
 * 其他入库
 */
export default {
    name: "warehouse-otherIn"
}
</script>

<script lang="tsx" setup>
import { ref } from "vue"
import { definePageModel, PageModel } from "@/frame/view/layout/page-model/constructor.ts"
import OrderDetail from "./components/order-detail/index.vue"
import OrderForm from "./components/order-form/index.vue"
import { ExamStatus } from "./warehouse-otherIn";
import { ElMessage, ElMessageBox } from "element-plus";
import { processRequest } from "@/frame/apis/request";

/**
 * 页面配置
 */
const pageModelRef = ref()
const config = definePageModel<any>({
    url: "/api/WarehouseOtherIn",
    searchForm: {
        els: [
            {
                eType: 'el-input',
                prop: "code",
                props: {
                    placeholder: "单据编码",
                    clearable: true
                }
            },
            {
                eType: 'el-select',
                prop: "examStatus",
                props: {
                    placeholder: "审核状态",
                    clearable: true
                },
                optionsData: {
                    list: [
                        {
                            label: "待审核",
                            value: 0
                        },
                        {
                            label: "审核通过",
                            value: 1
                        },
                        {
                            label: "审核不通过",
                            value: 2
                        }
                    ],
                    label: "label",
                    value: "value"
                }
            }
        ]
    },
    programForm: {
        els: [
            {
                label: "新增",
                eType: "el-button",
                props: {
                    type: "primary"
                },
                event: "add"
            }
        ]
    },
    table: {
        page: {
            enable: true,
            pageSize: 20
        },
        props: {
            stripe: false,
            border: false
        },
        operation: {
            width: 300,
            props: {
                fixed: "right"
            },
            els: [
                {
                    eType: "el-button",
                    label: "审核通过",
                    event: "pass",
                    props: {
                        type: "primary",
                        link: true
                    },
                    hide: false
                },
                {
                    eType: "el-button",
                    label: "审核不通过",
                    event: "un-pass",
                    props: {
                        type: "primary",
                        link: true
                    },
                    hide: false
                },
                {
                    eType: "el-button",
                    label: "反审核",
                    event: "cancel-pass",
                    props: {
                        type: "primary",
                        link: true
                    },
                    hide: false
                },
                {
                    eType: "el-button",
                    label: "详情",
                    event: "detail",
                    props: {
                        type: "primary",
                        link: true
                    },
                    hide: false
                }
            ]
        },
        els: [
            {
                label: "单据编码",
                prop: "code",
                minWidth: 120
            },
            {
                label: "审核状态",
                prop: "examStatus",
                minWidth: 120,
                renderFn(data) {
                    return <span>{ExamStatus[data.examStatus]}</span>
                }
            },
            {
                label: "备注",
                prop: "remark",
                minWidth: 200
            },
            {
                label: "制单时间",
                prop: "createTime",
                minWidth: 200
            }
        ]
    }
})

/**
 * 详情
 */
const orderDetailRef = ref()
const handleDetail = (row: any) => {
    orderDetailRef.value.show({
        id: row.id
    })
}

/**
 * 新增
 */
const orderFormRef = ref()
const handleAdd = () => {
    orderFormRef.value.show()
}

/**
 * 刷新
 */
const handleRefresh = () => {
    pageModelRef.value.refreshTableData()
}


/**
 * 审核
 */
const handlePass = async (row: any) => {
    await ElMessageBox.confirm("是否确认审核通过?", "审核", {
        type: "warning"
    })
    await processRequest.post("/api/WarehouseOtherIn/pass?id=" + row.id)
    ElMessage.success("审核通过")
    handleRefresh()
}

/**
 * 审核不通过
 */
const handleUnPass = async (row: any) => {
    await ElMessageBox.confirm("是否确认审核不通过?", "审核", {
        type: "warning"
    })
    await processRequest.post("/api/WarehouseOtherIn/UnPass?id=" + row.id)
    ElMessage.success("审核不通过成功")
    handleRefresh()
}

/**
 * 反审核
 */
const handleCancelPass = async (row: any) => {
    await ElMessageBox.confirm("是否确认反审核?", "反审核", {
        type: "warning"
    })
    await processRequest.post("/api/WarehouseOtherIn/CancelPass?id=" + row.id)
    ElMessage.success("反审核成功")
    handleRefresh()
}
</script>

<template>
    <PageModel ref="pageModelRef" :PageModel="config" @detail="handleDetail" @add="handleAdd" @pass="handlePass"
        @un-pass="handleUnPass" @cancel-pass="handleCancelPass" />

    <OrderDetail ref="orderDetailRef" />

    <OrderForm ref="orderFormRef" @confirm="handleRefresh" />
</template>